package com.nervenets.web.hibernate.domain;

import com.nervenets.web.enumeration.*;
import com.nervenets.web.hibernate.DomainObject;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Index;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;

/**
 * 账户流水
 * Created by Joe on 2018/1/6.
 */
@Entity
@Table(name = "user_wealth_flows")
@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
@AllArgsConstructor
public class WealthFlow extends DomainObject {
    @Index(name = "_idx_user_wealth_flows_userId")
    private long userId;//用户ID或代理商ID
    private long offset;//变动值，单位（厘）
    private long surplus;//结余，单位（厘）
    private long total;//累计，单位（厘）
    @Column(name = "wt", columnDefinition = "tinyint")
    private WealthType wealthType = WealthType.money;
    @Column(name = "ot", columnDefinition = "tinyint")
    @Index(name = "_idx_user_wealth_flows_operateType")
    private OperateType operateType = OperateType.recharge;//仅记录操作行为，便于数据快速索引，查询详情可根据日期去相应的地方查询
    @Column(name = "fs", columnDefinition = "tinyint")
    @Index(name = "_idx_user_wealth_flows_flowStatus")
    private FlowStatus flowStatus = FlowStatus.success;
    @Column(name = "pt", columnDefinition = "tinyint")
    private PayType payType = PayType.surplus;
    @Column(name = "ut", columnDefinition = "tinyint")
    private UnionType unionType = UnionType.normal;
    @Index(name = "_idx_user_wealth_flows_unionId")
    private long unionId = 0;
    @Index(name = "_idx_user_wealth_flows_ip")
    private long ip = 0;
    private String detail;

    public WealthFlow(long userId, long offset, long surplus, OperateType operateType, long ip) {
        this.userId = userId;
        this.offset = offset;
        this.surplus = surplus;
        this.operateType = operateType;
        this.ip = ip;
    }

    public WealthFlow(long userId, long offset, long surplus, OperateType operateType, long ip, long unionId, UnionType unionType, String detail) {
        this(userId, offset, surplus, operateType, ip);
        this.unionType = unionType;
        this.unionId = unionId;
        this.detail = detail;
    }
}
